<template>
  <basic-dialog
    :visible="visible"
    :title="'合同查看'"
    :show-footer="false"
    :handle-close="onCancel"
    :handle-open="getTableData"
    :width="'70%'"
  >
    <BasicList
      :data-source="list"
      :columns="columns"
      :tableHeight="300"
      :show-select-col="false"
      :show-pagination="false"
    />
  </basic-dialog>
</template>
<script>
import BasicDialog from '@sourcing/components/BasicDialog';
import BasicList from '@sourcing/components/BasicList';
import { queryContractInfoService } from '@/api/sourcing/purchaseInquiry';

export default {
  name: 'QualifieDialog',
  components: {
    BasicDialog,
    BasicList,
  },
  props: {
    visible: {
      type: Boolean,
    },
    sourcingBillId: {
      type: [String, Number],
    }
  },
  data () {
    return {
      list: [],
      columns: [
        {
          prop: 'supplierName',
          label: '供应商名称',
        },
        {
          prop: 'signContractStr',
          label: '是否签订合同',
          width: 100
        },
        {
          prop: 'noSignContractReason',
          label: '不签订合同原因',
          width: 120
        },
        {
          prop: 'contractName',
          label: '合同附件',
          render: (h, { row }) => {
            return <a onClick={() => this.downloadContract(row)} type="primary">{ row.contractName }</a>
          }
        },
        {
          prop: 'creationUser',
          label: '上传人',
          width: 80
        },
        {
          prop: 'creationDate',
          label: '上传时间',
          width: 150
        },
      ],
    };
  },
  methods: {
    async getTableData () {
      const res = await queryContractInfoService({ sourcingBillId: this.sourcingBillId })
      this.list = res.data;
    },
    onCancel () {
      this.$emit('update:visible', false);
    },
    downloadContract (row) {
      if (!row.supplierContractId) {
        return this.$message.error('文件异常');
      }
      window.location.href = `${window.location.origin}/srm-api/orderInquiry/downloadContract?supplierContractId=${row.supplierContractId}`
    }
  },
};
</script>
